//
//  LSTextAttachment.swift
//  新浪微博---01次
//
//  Created by 李宗帅 on 16/5/15.
//  Copyright © 2016年 LS. All rights reserved.
//

import UIKit

class LSTextAttachment: NSTextAttachment {
    
    var emoticon: LSEmoticon?
    
    // 抽取获取 表情 AttributeString的方法
    class func getEmoticonAttributeString(emoticon: LSEmoticon,fontHeigth: CGFloat) -> NSAttributedString{
        
        // 1.创建一个 附件的实例对象
        let attachemnt = LSTextAttachment()
        
        attachemnt.emoticon = emoticon
        // 设置属性
        let iamgeName = "\(emoticon.package!)/\(emoticon.png!)"
        attachemnt.image = UIImage(named: iamgeName)
        // 设置图片的宽高 -- 注意 textView.font 是可选
        //        let fontHeigth = self.font!.lineHeight
        // bounds
        attachemnt.bounds = CGRectMake(0, -4, fontHeigth, fontHeigth)
        // 2.把附件赋值给 attributeString
        let attribute = NSAttributedString(attachment: attachemnt)
        
        return attribute
    }

    
}
